package com.cell.controller;


import com.cell.common.Result;
import com.cell.common.States;
import com.cell.pojo.entity.user.pointaccount.UserPointOperate;
import com.cell.service.user.IUserPointAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpRequest;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author cloudJiang
 * @since 2022-06-04
 */
@RestController
@RequestMapping("/userPointAccount")
@Api(tags = "用户积分账户操作相关接口")
public class UserPointAccountController {
    @Autowired
    IUserPointAccountService pointAccountService;

    /**
     * 使用积分兑换积分商城中的商品，判断是否可以兑换，兑换成功则生成记录
     *
     * @param pointAccountId
     * @param productId
     * @return
     */
    @ApiOperation(value = "积分兑换商品", notes = "使用积分兑换积分商城中的商品，判断是否可以兑换，兑换成功则生成记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pointAccountId", value = "用户的积分账户", required = true),
            @ApiImplicitParam(name = "productId", value = "商品ID", required = true)
    })
    @GetMapping("/redeemProduct")
    Result redeemProduct(Long pointAccountId, Long productId) {
        pointAccountService.redeemProduct(pointAccountId, productId);
        return new Result(null,
                States.OK.getStates(), States.OK.getDescription());
    }

    /**
     * 获取积分账单明细
     *
     * @return
     */
    @ApiOperation(value = "获取积分账单明细", notes = "查看积分变更历史")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "accountId", value = "用户的积分账户", required = true),
            @ApiImplicitParam(name = "operate", value = "操作，收入为save，支出为take")
    })
    @GetMapping("/getOperateHistory")
    Result getOperateHistory(Long accountId, String operate) {

        return new Result(pointAccountService.getOperateHistory(accountId, operate),
                States.OK.getStates(), States.OK.getDescription());
    }

    /**
     * 删除积分订单记录
     *
     * @return
     */
    @ApiOperation(value = "删除积分订单记录", notes = "调用deleteOperateHistory方法，使用operateId参数来删除积分订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "operateId", value = "积分订单ID", paramType = "Long", required = true)
    })
    @GetMapping("/deleteOperateHistory")
    Result deleteOperateHistory(@RequestParam("operateId") Long operateId) {
        pointAccountService.deletePointOperate(operateId);
        return new Result(null, States.OK.getStates(), States.OK.getDescription());
    }
} 

